package com.woniuxy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.dao.DrvingRecordMapper;
import com.woniuxy.pojo.DrvingRecord;
import com.woniuxy.service.DrvingRecordService;
import com.woniuxy.util.DataGridView;
import com.woniuxy.vo.DrvingRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class DrvingRecordImpl implements DrvingRecordService{
    @Autowired
    private DrvingRecordMapper drvingRecordMapper;

    @Override
    public DataGridView selectDrvingRecordsByProperty(DrvingRecordVo drvingRecordVo) {
        Page<Object> page = PageHelper.startPage(drvingRecordVo.getPage(), drvingRecordVo.getLimit());
        List<DrvingRecord> drvingRecords = this.drvingRecordMapper.selectDrvingRecordsByProperty(drvingRecordVo);
        return new DataGridView (page.getTotal(),drvingRecords);
    }
    @Transactional
    @Override
    public void deleteDrvingRecordById(int id) {
        drvingRecordMapper.deleteDrvingRecordById(id);
    }
    @Transactional
    @Override
    public void removeBatchDrvingRecord(Integer[] ids) {
        if (ids!=null&&ids.length>0){
            for (Integer id:ids){
                this.deleteDrvingRecordById(id);
            }
        }
    }
    @Transactional
    @Override
    public boolean insertDrvingRecord(DrvingRecord drvingRecord) {
        boolean flag=false;
        int i = this.drvingRecordMapper.insertDrvingRecord(drvingRecord);
        if(i>0){
            flag=true;
        }
        return flag;
    }
    @Transactional
    @Override
    public boolean updataDrvingRecord(DrvingRecord drvingRecord) {
        boolean flag=true;
        int i = this.drvingRecordMapper.updataDrvingRecord(drvingRecord);
        if (i>0){
            flag=true;
        }
        return flag;
    }

}
